<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="white">
    <link rel="stylesheet" href="../dist/main.css">
</head>
<body>
<script src="../dist/main.js"></script>
<div id="zc">
    <div class="center">
        <img src="" alt="logo" id="logo">
        <p id="zcTitle"></p>
    </div>

      <div class="box">

          <input type="text" placeholder="邮箱" id="mail">
          <div class="inputBox">
              <input type="text" placeholder="邮箱验证码" id="code">
              <button id="getCode">获取验证码</button>
          </div>

              <div class="mui-input-row">
                  <input type="password" placeholder="请输入密码" class="mui-input-password" id="pass">

              </div>
          <div class="mui-input-row">
              <input type="password" placeholder="再次输入密码" class="mui-input-password" id="pass2">

          </div>
         <div id="check">
             <i class="mui-icon mui-icon-checkmarkempty" style="display: none"></i>

         </div>
          <span class="read">阅读并且同意我们的 <a id="agreement">《用户注册协议》</a></span>
          <button id="zcBtn" class="sureButton" >注册</button>
          <a id="hasLogin">已有账号去登录</a>

      </div>
    
</div>
<script>
    $("title").html(mt5Obj.title)
    $("#zcTitle").html(mt5Obj.zcTitle)
    var check=true;
    var bol=true;
    if(window.location.search.split("?")[1]=="2"){
        $("#check").children().show();
        check=false;
    }
     console.log(window.location.search.split("?")[1])

    $("#logo").attr("src",mt5Obj.logo);

    //自定义选择框
    mui("body").on('tap','#check',function(){
        if(check){
            $(this).children().show();
            check=false;
        }else {
            $(this).children().hide();
            check=true;
        }

    })

//    获取验证码
    mui("body").on('tap','#getCode',function(){
        var mail=$("#mail").val();
       if (emailGe(mail,$("#mail"))){
             return false;
       }else{
           setCode($(this),bol)

           if(bol){
               $.ajax({
                   url: mt5Obj.allUrl+"users/send/mail/code",
                   type:"post",
                   data:{
                       toAddress:mail,

                   },
                   success: function(data){
                       if(data.data){
                           mui.alert("发送成功！");

                       }
                   }
               });
           }

       }


    })
    //注册按钮
    mui("body").on('tap','#zcBtn',function(){

        var mail=$("#mail").val();
        var pass=$("#pass").val();
        var pass2=$("#pass2").val();
        var code=$("#code").val();
        if (emailGe(mail,$("#mail"))){
            return false;
        }else if(pass=="" || pass2==""){
            mui.alert("密码不能为空！");

        }else if(pass.length<6){
            mui.alert("密码最少6位数！");

        }
        else if(pass!=pass2){
            mui.alert("两次输入密码不相符，请重新输入！");

        }else if(code==""){
            mui.alert("请输入邮箱验证码！");

        }else if(check){
            mui.alert("请同意勾选用户使用协议")
        }
        else{
            $.ajax({
                url: mt5Obj.allUrl+"users/wx/register ",
                type:"post",
                data:{
                    mail:mail,
                    password:pass,
                    mailValidationCode:code,
                },
                success: function(data){
                    if(data.data){
                        mui.openWindow({
                            id:'zcSuccess',
                            url:'zcSuccess.html'
                        });
                        sessionStorage.setItem("zcMail",mail);
                    }else{
                        mui.alert("注册失败")
                    }
                }
            });
        }


    })

    //判断邮箱是否重复
    $("#mail").blur(function () {
        var mail=$("#mail").val();
        if (emailGe(mail,$("#mail"))){
            return false;
        }else{
            $.ajax({
                url: mt5Obj.allUrl+"users/validate/mail",
                type:"get",
                data:{
                    mail:mail
                },
                success: function(data){
                    if(data.data){
                        mui.alert("此邮箱已被注册，请重新输入")
                    }
                }
            })
        }

    })
   //点击用户协议
    mui("body").on('tap','#agreement',function(){
        mui.openWindow({
            id:'agreement',
            url:'agreement.html'
        });

    })
    goLogin()
    removeWarn()

</script>

</body>
</html>


